package com.bluefox.hospital.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bluefox.common.web.exception.CustomRuntimeException;
import com.bluefox.hospital.service.LeaderService;
import com.bluefox.hospital.model.Leader;
import com.bluefox.hospital.repository.LeaderRepository;
import lombok.NonNull;

/**
 * LeaderService 实现类
 */
@Service
@Transactional
public class LeaderServiceImpl implements LeaderService {

    @Autowired
    private LeaderRepository leaderRepository;

    @Override
    @Transactional(readOnly = true)
    public Leader get(@NonNull Long id) {
        final  Leader model = leaderRepository.findById(id).get();
        if (model == null) {
            throw new CustomRuntimeException("404", String.format("查找的资源[%s]不存在.", id));
        }
        return model;
    }

    @Override
    public Leader create(Leader model) {
        // TODO: 业务逻辑
        return leaderRepository.save(model);
    }

    @Override
    public Leader update(Leader model) {
        // TODO: 业务逻辑
        return leaderRepository.save(model);
    }

    @Override
    public void delete(@NonNull Long id) {
        // TODO: 业务逻辑
        leaderRepository.deleteById(id);
    }
}
